package o2o.config.dao;

import o2o.config.init.AutoWiredClass;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.SQLException;

public class UserDaoSql extends DaoImpl {

    private static UserDaoSql dao = null;

    // 单例模式获取dao对象
    public static UserDaoSql getInstance() {
        if (dao == null) {
            dao = new UserDaoSql();
        }
        return dao;
    }

    public Connection getConnection() throws SQLException {
        return AutoWiredClass.userSource2.getConnection();
    }

    public Connection getConnection(boolean openTransaction) throws SQLException {
        Connection conn = AutoWiredClass.userSource2.getConnection();
        if (openTransaction) {
            conn.setAutoCommit(false);
        }
        return conn;
    }

}
